print("======类========")


class Student:
    name: str
    age: int
    url = None
    __status = True  # 私有属性

    # 构造方法
    def __init__(self, name, age, url):
        self.name = name
        self.age = age
        self.url = url
        print("有参构造方法")

    # 私有方法
    def __privateTest(self):
        if self.__status:
            print("状态正常")
        else:
            print("状态b不正常")

    # 普通方法
    def test(self):
        print(f"{self.name} this is test")
        self.__privateTest()


stu = Student("zzzz", 18, "httt")

stu.name = "zzz"
stu.age = 18
stu.url = "http://localhost:8080:"

print(stu.url)
stu.test()

print(stu.url)
stu.url = 18
print(stu.url)

print("======继承========")


class A:
    a: int

    def at(self):
        print("this is a")


class B:
    b: int

    def bt(self):
        print("this is b")


# 单继承
class One(A):
    def test(self):
        print("单继承")


# 多继承
class Many(A, B):
    def test(self):
        print("多继承")

    def at(self):
        print("this is aaa")
        A.at(self)


many = Many()
many.test()
many.at()
many.bt()


def test(x: int, y: int):
    return x + y


def test2(x: int, y: int) -> int:
    return x + y


n = test(1, 5)
print(n)

# union类型
from typing import Union

my_list: list[Union[int, str]] = ["test", 1, 2]


def test(data: Union[int, str]) -> Union[int]:
    pass


print("==========多态=======")


# 抽象类
class Animal:
    # 抽象方法
    def speak(self):
        pass

class Dog(Animal):
    def speak(self):
        print("dog")

class Cat(Animal):
    def speak(self):
        print("cat")


def test_speak(animal:Animal):
    animal.speak()


dog=Dog()
cat=Cat()
test_speak(dog)
test_speak(cat)